package com.efast.cafe.portal.security.filter;



import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.authentication.AuthenticationServiceException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import com.efast.cafe.portal.security.core.AuthenticationFactory;


/**
 * 
    * @ClassName: MyUsernamePasswordAuthenticationFilter
    * @Description: 自定义的用户登录filter 增加了companyCode的参数
    * @author xuanming.feng
    * @date 2018年8月3日
    *
 */
public class MyUsernamePasswordAuthenticationFilter extends UsernamePasswordAuthenticationFilter{
	
	
	
	@Override
	public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response){
		if (!request.getMethod().equals("POST")) {
			throw new AuthenticationServiceException("-1");
		}
		UsernamePasswordAuthenticationToken authRequest = AuthenticationFactory.authenticationToken(request, response);
		setDetails(request, authRequest);
		return this.getAuthenticationManager().authenticate(authRequest);
	}
	
}
